﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RastinArgham.CRM.Business;
using Mani.Common.Security;

namespace RastinArgham.CRM.Web
{
    public partial class default_am_settings : System.Web.UI.Page
    {
        public ISecurityManager securityManager { get; set; }
        public CRMRepository crmRepository { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (securityManager == null)
            {
                securityManager = new SecurityManager();
                securityManager.authProvider = new WebAuthorizationProvider();
            }

            if (crmRepository == null)
                crmRepository = new CRMRepository();

            if (!securityManager.IsActionPermitted("default_am_addedit"))
                Response.Redirect("~/access_denied.aspx");

            if (!Page.IsPostBack)
                LoadAMSettings();
        }

        private void LoadAMSettings()
        {
            gvDefaultAccountManagers.DataSource = crmRepository.GetDefaultAccountManagers();
            gvDefaultAccountManagers.DataBind();
        }

        protected void gvDefaultAccountManagers_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvDefaultAccountManagers.PageIndex = e.NewPageIndex;
            LoadAMSettings();
        }
    }
}